package com.ewanghuiju.app.presenter.resale;

import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.resale.ResaleOrderListContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.PintuanOrderListResponBean;
import com.ewanghuiju.app.model.bean.response.ResaleOrderListResponBean;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class 转售订单
 * @time 2020/2/16
 */
public class ResaleOrderListPresenter extends RxPresenter<ResaleOrderListContract.View> implements ResaleOrderListContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public ResaleOrderListPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getData(int page, int order_type) {
        addSubscribe(mDataManager.getPtiorderList(page, order_type, "1")
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<List<PintuanOrderListResponBean>>>(mView) {
                    @Override
                    public void onNext(Optional<List<PintuanOrderListResponBean>> optional) {

                        List<PintuanOrderListResponBean> tempList = optional.getIncludeNull();
                        List<ResaleOrderListResponBean> list = new ArrayList<>();
                        for (PintuanOrderListResponBean bean : tempList) {
                            ResaleOrderListResponBean resaleOrderListResponBean = new ResaleOrderListResponBean();
                            resaleOrderListResponBean.setGoods_title(bean.getGoods_name());
                            resaleOrderListResponBean.setGoods_img(bean.getImage());
                            list.add(resaleOrderListResponBean);
                        }
                        if (mView != null)
                            mView.showContent(list);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        if (mView != null)
                            mView.showContentError();
                    }
                })
        );
    }

}
